package com.nageoffer.aicloud.controller;

import com.nageoffer.aicloud.common.convention.result.Result;
import com.nageoffer.aicloud.common.convention.result.Results;
import com.nageoffer.aicloud.dto.req.UserLoginReqDTO;
import com.nageoffer.aicloud.dto.req.UserRegisterReqDTO;
import com.nageoffer.aicloud.dto.resp.UserLoginRespDTO;
import com.nageoffer.aicloud.service.UserService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户接口控制层
 */
@RestController
@RequiredArgsConstructor
public class UserController {
    private final UserService userService;

    @PostMapping("/api/ai-cloud/v1/user/login")
    public Result<UserLoginRespDTO> userLogin(@RequestBody @Validated UserLoginReqDTO requestParam, HttpServletRequest request) {
        return Results.success(userService.userLogin(requestParam, request));
    }

    @PostMapping("/api/ai-cloud/v1/user/register")
    public Result<Void> userRegister(@RequestBody @Validated UserRegisterReqDTO requestParam) {
        userService.userRegister(requestParam);
        return Results.success();
    }
}
